$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'serialbox'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|

end

def generate_tester_classes(prefix, serialize_with)
  eval <<-RUBY
    class #{prefix}SerializeMethodTester
      attr_accessor :var
      def initialize(var) self.var = var end

      include SerialBox
      serialize_with #{serialize_with.inspect}
      serialize_fields { |s| s.serialize :var }
    end

    class #{prefix}SerializeIvarTester
      def initialize(var) @var = var end

      include SerialBox
      serialize_with #{serialize_with.inspect}
      serialize_fields { |s| s.serialize :@var }
    end

    class #{prefix}SerializeIntoTester
      attr_accessor :var
      def initialize(var) self.var = var end

      include SerialBox
      serialize_with #{serialize_with.inspect}
      serialize_fields { |s| s.serialize :var, :into => :custom }
    end


    class #{prefix}SerializerMethodTester
      def initialize(var) @var = var end
      def var_setter(val) @var = val end
      def var_getter() @var end

      include SerialBox
      serialize_with #{serialize_with.inspect}
      serialize_fields do |s|
        s.serializer 'var_json', :var_getter
        s.deserializer 'var_json', :var_setter
      end
    end

    class #{prefix}SerializerBlockTester
      def initialize(var) @var = var end

      include SerialBox
      serialize_with #{serialize_with.inspect}
      serialize_fields do |s|
        s.serializer('var_json') { @var }
        s.deserializer('var_json') { |val| @var = val }
      end
    end
  RUBY
end
